﻿<%
'作者：山林客（ah_bill）
'博客：http://ruizhinet.blog.163.com
'网站：http://www.ruizhinet.cn
'本信息不会影响您网站的正常访问，请保留
if RZ_IN<>1 then
	response.write("非法请求")
	response.end
end If

Function ShowTypeOptions(use_case,myid,mypath,myparentid,myfenlei,withpath)
	dim sql_where,sqlTypeParent,rsTypeParent
	sql_where=""
	select case use_case
		case "add_modify_article":
			sql_where=" and fenlei=1 "
		case "add_modify_product":
			sql_where=" and fenlei=2 "
		case "add_modify_photo":
			sql_where=" and fenlei=3 "
		case "add_modify_job":
			sql_where=" and fenlei=7 "
		case "add_modify_comment":
			sql_where=" and fenlei=5 "
		case "showallparenttypes":
			sql_where=" and (fenlei<>4) "
		case "move_type":
			If myparentid<>0 Then 
			sql_where= "and id<>"&myid&" and id<>"&myparentid&" and fenlei="&myfenlei
			Else
			sql_where= "and id<>"&myid&"  and fenlei="&myfenlei
			End If 
		case "union_type"
			sql_where= "and id<>"&myid&" and fenlei="&myfenlei
	end select
	sqlTypeParent = "select * from [c_type] where  parentid=0  "&sql_where&"  order by visible desc,theorder"
	Set rsTypeParent = Server.CreateObject("ADODB.Recordset")
	rsTypeParent.open sqlTypeParent,conn,1,1
	if rsTypeParent.eof or rsTypeParent.bof Then
		If use_case="union_type" Then 
			response.redirect("showmsg.asp?from=type_list.asp&msg=NoFenlei")
		End If 
	else
	Do While Not rsTypeParent.eof
		If withpath=0 then
			response.write("<option value='"&rsTypeParent("id"))
		Else
			response.write("<option value='"&rsTypeParent("id")&"_"&rsTypeParent("path")&"")
			If use_case="move_type" Then
				response.write("_"&rsTypeParent("thelevel"))
			End If 
		End If 
		response.write("'")
		If use_case="add_modify_article" or use_case="add_modify_product" or use_case="add_modify_photo" or use_case="add_modify_job" or use_case="add_modify_comment" Or use_case="showallparenttypes" Then 
			If myid<>"" And InStr(","&myid&",",","&rsTypeParent("id")&",")>0 Then 
				response.write(" selected='true'")
			End If
			If rsTypeParent("havechild")=1 Then
				response.write(" class='havechild'")
			End If
		End If 
		response.write(">")
		dim i
		For i=1 To rsTypeParent("thelevel")-2
			response.write("&nbsp;&nbsp;")
		Next
		If(rsTypeParent("thelevel")>2) Then
			response.write("└")
		End If 
		If S_LANG=1 Then
			response.write(rsTypeParent("engname"))
			If rsTypeParent("visible")=0 Then 
				response.write("(hidden)")
			End If 
		Else
			response.write(rsTypeParent("name"))
			If rsTypeParent("visible")=0 Then 
				response.write("(隐藏)")
			End If 
		End If
		response.write("</option>")
		Call PrintChild(use_case,myid,mypath,myparentid,rsTypeParent("id"),myfenlei,withpath)
	rsTypeParent.movenext
	Loop
	end if
	rsTypeParent.close
	Set rsTypeParent=Nothing
End Function

Function PrintChild(use_case,myid,mypath,myparentid,parentid,myfenlei,withpath)
	dim sql_where,sqlTypeChild,rsTypeChild
	sql_where=""
	select case use_case
		case "add_modify_article":
			sql_where=" and fenlei=1 "
		case "add_modify_product":
			sql_where=" and fenlei=2 "
		case "add_modify_photo":
			sql_where=" and fenlei=3 "
		case "showallparenttypes":
			sql_where=" and (fenlei<>4) "
		case "add_modify_comment":
			sql_where=" and fenlei=5 "
		case "union_type":
			sql_where= "and id<>"&myid&" and Instr(path,'"+mypath+"')<=0 and fenlei="&myfenlei
		case "move_type":
			sql_where= "and id<>"&myid&" and id<>"&myparentid&" and  Instr(path,'"+mypath+"')<=0 and fenlei="&myfenlei
	end select
	sqlTypeChild = "select * from [c_type] where   parentid="&parentid&"  "&sql_where&"  order by visible desc, theorder"
	Set rsTypeChild = Server.CreateObject("ADODB.Recordset")
	rsTypeChild.open sqlTypeChild,conn,1,1
	Do While Not rsTypeChild.eof
		If withpath=0 Then
			response.write("<option value='"&rsTypeChild("id"))
		else
			response.write("<option value='"&rsTypeChild("id")&"_"&rsTypeChild("path"))
			If use_case="move_type" Then
				response.write("_"&rsTypeChild("thelevel"))
			End If 
		End If 
		response.write("'")
		If use_case="add_modify_article" or use_case="add_modify_product" or use_case="add_modify_photo" or use_case="add_modify_job" or use_case="add_modify_comment" Or use_case="showallparenttypes" Then 
			If myid<>"" And InStr(","&myid&",",","&rsTypeChild("id")&",")>0 Then
				response.write(" selected='true'")
			End If
			If rsTypeChild("havechild")=1 Then
				response.write(" class='havechild'")
			End If
		End If 
		response.write(">")
		dim i
		For i=1 To rsTypeChild("thelevel")-2
			response.write("&nbsp;&nbsp;")
		Next
		If(rsTypeChild("thelevel")>2) Then
			response.write("└")
		End If 
		If S_LANG=1 Then
			response.write(rsTypeChild("engname"))
			If rsTypeChild("visible")=0 Then 
				response.write("(hidden)")
			End If 
		Else
			response.write(rsTypeChild("name"))
			If rsTypeChild("visible")=0 Then 
				response.write("(隐藏)")
			End If
		End If
		response.write("</option>")
		Call PrintChild(use_case,myid,mypath,myparentid,rsTypeChild("id"),myfenlei,withpath)
	rsTypeChild.movenext
	Loop
	rsTypeChild.close
	Set rsTypeChild=Nothing
End Function 

Function ShowMyChild(use_case,myid)
	dim sql_where,add_url,listurl,sqlMy,rsMy
	if myid="" then
		myid=0
	end if
	sql_where=""
	add_url=""
		select case use_case
		case "article":
			sql_where=" and fenlei=1 "
			add_url="article_add.asp"
		case "product":
			sql_where=" and fenlei=2 "
			add_url="product_add.asp"
		case "photo":
			sql_where=" and fenlei=3 "
			add_url="photo_add.asp"
		case "job":
			sql_where=" and fenlei=7 "
			add_url="job_add.asp"
		case "guestbook":
			sql_where=" and fenlei=5 "
			add_url=""
	end select
	sqlMy = "select * from [c_type] where  parentid="&myid&""&sql_where&"  order by visible desc, theorder"
	Set rsMy = Server.CreateObject("ADODB.Recordset")
	rsMy.open sqlMy,conn,1,1
	if not rsMy.eof then
		response.Write("<ul>")
		Do While Not rsMy.eof
			listurl="article_list.asp?lang="&S_LANG&"&id="&rsMy("id")
			if rsMy("fenlei")=2 then
				listurl="product_list.asp?lang="&S_LANG&"&id="&rsMy("id")
			end if
			if rsMy("fenlei")=3 then
				listurl="photo_list.asp?lang="&S_LANG&"&id="&rsMy("id")
			end If
			if rsMy("fenlei")=7 then
				listurl="job_list.asp?lang="&S_LANG&"&id="&rsMy("id")
			end If
			if rsMy("fenlei")=5 then
				listurl="comment_list.asp?id="&rsMy("id")
			end if
			response.write("<li>")
			response.Write("<a href='"&listurl&"'>")
			If S_LANG=1 Then
				response.Write(rsMy("engname"))
			Else
				response.Write(rsMy("name"))
			End If
			response.Write("</a>")
			response.Write("</li>")
		rsMy.movenext
		Loop
		response.Write("</ul>")
	Else
		response.write("<ul><li>")
		If add_url<>"" Then 

		response.Write("<a href="""&add_url&"?lang="&S_LANG&"&typeid="&typeid&""">")
		If S_LANG=1 Then 
			response.write("Add Record")
		Else
			response.write("添加记录")
		End If
		response.write("</a>")
		response.write("</li>")
		End if
		response.write("<li><a href=""javascript:history.go(-1)"">Back</a>")
		response.write("</ul>")
	end if
	rsMy.close
	Set rsMy=Nothing
End Function

Function ShowSpecialOption(myspecialid)
	dim rsd,sqld
	Set rsd = Server.CreateObject("ADODB.Recordset")
	sqld = "select * from [c_special] order by visible desc, id desc"
	rsd.open sqld,conn,1,1
	Do While Not rsd.eof
		response.write("<option value='"&rsd("id")&"'")
		if myspecialid<>"" then
			if rsd("id")=myspecialid then
				response.write(" selected='true'")
			end if 
		end if
		If S_LANG=1 Then
			response.write(">"&rsd("specialengname")&"</option>")
		Else
			response.write(">"&rsd("specialname")&"</option>")
		End If
	rsd.movenext
	Loop
	rsd.close
	Set rsd=Nothing
End Function

Function ShowTemplateOption_SQL(mytemplatepath)
	dim rsd,sqld
	Set rsd = Server.CreateObject("ADODB.Recordset")
	sqld = "select * from [c_template] order by id desc"
	rsd.open sqld,conn,1,1
	Do While Not rsd.eof
		response.write("<option value='"&rsd("temp_path")&"'")
		if mytemplatepath<>"" then
			if rsd("temp_path")=mytemplatepath then
				response.write(" selected='true'")
			end if 
		end if
		response.write(">"&rsd("tem_name")&"</option>")
	rsd.movenext
	Loop
	rsd.close
	Set rsd=Nothing
End Function

Function ShowTemplateOption(mytemplatepath)
	Dim fso,objFolder,objSubFolders,objSubFolder
	set fso=server.CreateObject("scripting.filesystemobject")
	on error resume next
	set objFolder=fso.GetFolder(Server.Mappath("../template"))
	set objSubFolders=objFolder.Subfolders
	for each objSubFolder in objSubFolders 
	Response.Write("<option value='"&objSubFolder.name&"'")
	If mytemplatepath=objSubFolder.name Then
	response.write(" selected")
	End If
	response.Write(">"&objSubFolder.name&"</option>")
	next
	set objFolder=nothing
	set objSubFolders=nothing
	set fso=nothing
End Function

If app("rz_savelog")=1 Then
	Call SaveLog()
End If 

Function SaveLog()

Dim username,actionip,actionids,actionurl,actiontime,actionname
username=session("user_name")
If username="" Then
	username=HTMLEncode(request.Form("name"))
End if
actionip=request.ServerVariables("REMOTE_ADDR")
actionids=HTMLEncode(request("id"))
If actionids="" Then
actionids=HTMLEncode(request("filename"))
End If
actionurl=request.ServerVariables("SCRIPT_NAME")
actiontime=Now()
If InStr(actionurl,"loginchk")>0 Or InStr(actionurl,"logout")>0 Or  InstrRev(actionurl,"_delete")>0 Or InstrRev(actionurl,"_save")>0 Or InStr(actionurl,"manage_database")>0 Or InStr(actionurl,"manage_imgpath")>0 Or InStr(actionurl,"manage_sqlinj")>0 Or InStr(actionurl,"manage_upload")>0 Or InStr(actionurl,"manage_template")>0 Then
	If InStr(actionurl,"loginchk")>0 Then actionname="登陆"
	If InStr(actionurl,"logout")>0 Then actionname="退出"
	If InStr(actionurl,"advertise_")>0 Then actionname="广告"
	If InStr(actionurl,"article_")>0 Then  actionname="文章"
	If InStr(actionurl,"comment_reply_")>0 Then actionname="留言回复"
	If InStr(actionurl,"comment_")>0 And InStr(actionurl,"comment_reply_")=0 Then actionname="留言"
	If InStr(actionurl,"manage_database")>0 Then actionname="数据库管理"
	If InStr(actionurl,"manage_imgpath")>0 Then actionname="图片路径修改"
	If InStr(actionurl,"manage_sqlinj")>0 Then actionname="SQL注入管理"
	If InStr(actionurl,"manage_upload")>0 Then actionname="上传文件管理"
	If InStr(actionurl,"manage_template")>0 Then actionname="模板管理"
	If InStr(actionurl,"photo_")>0 Then actionname="图片"
	If InStr(actionurl,"product_")>0 Then actionname="商品"
	If InStr(actionurl,"special_")>0 Then actionname="专题"
	If InStr(actionurl,"type_")>0 Then actionname="分类"
	If InstrRev(actionurl,"_delete.asp")>0 Then actionname=actionname&"删除"
	If InstrRev(actionurl,"_save.asp")>0 Then actionname=actionname&"保存"

	Dim rst,sqlt
	Set rst = Server.CreateObject("ADODB.Recordset")
	sqlt = "select * from [c_log]"
	rst.open sqlt,conn,1,3
	rst.addnew
	rst("username")=username
	rst("actionip")=actionip
	rst("actionids")=actionids
	rst("actionurl")=actionurl
	rst("actiontime")=actiontime
	rst("actionname")=actionname
	rst.update
	rst.close
	Set rst=Nothing
End if
End Function

'发表/修改文章、图片、商品自动更新的时候生成相关HTML页面
Function MakeOneRecord(proc,id,typeid,specialid,fullpath,nowtime,lang)
	response.write("<br/>"&LongSpaceStr&"正在生成内容页...")
	Dim path,static_path,tablename,pagesize,listproc
	Dim rst,sqlt
	Set rst = Server.CreateObject("ADODB.Recordset")
	sqlt = "select perpage from [c_type] where id="&typeid
	rst.open sqlt,conn,1,1
	If Not rst.eof Then 
	pagesize=rst("perpage")
	End If 
	rst.close
	Set rst=Nothing 
	path=CutPath(fullpath)
	static_path=Replace(path,",","-")
	Call CreateFolders(GetPath(RZ_HTML_PATH&"/"&proc&"0/t"&static_path))
	Call CreateFolders(GetPath(RZ_HTML_PATH&"/"&proc&"1/t"&static_path))
	Select Case proc
	Case RZ_PRE_ARTICLE_SHOW:
		tablename="c_article"
		listproc=RZ_PRE_ARTICLE_LIST
	Case RZ_PRE_PRODUCT_SHOW:
		tablename="c_product"
		listproc=RZ_PRE_PRODUCT_LIST
	Case RZ_PRE_PHOTO_SHOW:
		tablename="c_photo"
		listproc=RZ_PRE_PHOTO_LIST
	Case RZ_PRE_JOB_SHOW:
		tablename="c_job"
		listproc=RZ_PRE_PHOTO_LIST
	End Select 
	Call ChangeStatic(1,lang)
	Dim filepath
	If specialid>0 Then 
		S_RZPARAM.QueryString=proc&lang&"-t"&path&"s"&specialid&"c"&id&".html"
		filepath=GetPath(RZ_HTML_PATH&"/"&proc&lang&"/t"&static_path&"/s"&specialid&"c"&id&".html")
	Else 
		S_RZPARAM.QueryString=proc&lang&"-t"&path&"c"&id&".html"
		filepath=GetPath(RZ_HTML_PATH&"/"&proc&lang&"/t"&static_path&"/c"&id&".html")
	End If 
	S_HTMLMBUFFER=""
	S_TEMPLATE=""
	Select Case proc
		Case RZ_PRE_ARTICLE_SHOW:
			Call ArticleShow(1)
		Case RZ_PRE_PRODUCT_SHOW:
			Call ProductShow(1)
		Case RZ_PRE_PHOTO_SHOW:
			Call PhotoShow(1)
		Case RZ_PRE_JOB_SHOW:
			Call JobShow(1)
	End Select 
	Call SaveFile(filepath,S_HTMLMBUFFER)
	
	response.write("<br/>"&LongSpaceStr&"正在生成首页...")

	Set S_RZPARAM=new RZPARAM
	S_RZPARAM.QueryString="default"&lang&".html"
	S_TEMPLATE=""
	S_HTMLMBUFFER=""
	Call Default(1)
	If app("rz_defaultlanguage")=lang Then 
		filepath=GetPath("index.html")
		Call SaveFile(filepath,S_HTMLMBUFFER)
	End If 
	filepath=GetPath("index"&lang&".html")
	Call SaveFile(filepath,S_HTMLMBUFFER)
	
	response.write("<br/>"&LongSpaceStr&"正在生成列表页...")

	
	Dim patharr,i,realpath
	realpath="0,"
	patharr=Split(path,",")
	For i=0 To UBound(patharr)
		realpath=realpath&patharr(i)&","
		Dim sqlu,rsu
		Set rsu = Server.CreateObject("ADODB.Recordset")
		sqlu = "select * from c_type where path='"&realpath&"'"
		rsu.open sqlu,conn,1,3
		If Not rsu.eof Then 
			rsu("makehtmltime")=nowtime
			rsu.update
		End If 
		rsu.close
		Set rsu=Nothing

		Dim sql,rs,num
		Set rs = Server.CreateObject("ADODB.Recordset")
		sql = "select count(*) as num from "&tablename&" where path like '%"&realpath&"%' and lang="&lang&""
		rs.open sql,conn,1,1
		If Not rs.eof Then 
			num=CaculatePage(rs("num"),pagesize)
			Call MakeList(listproc,CutPath(realpath),lang,0,num)
		End If 
		rs.close
		Set rs=Nothing 
	Next
	Response.Write("<br/>操作成功完成！")
End Function 

'列表页生成函数
Function MakeList(proc,path,lang,startpage,endpage)
	Dim static_path
	static_path=Replace(path,",","-")
	Dim page,filepath
	For page=startpage To endpage
		Call ChangeStatic(1,lang)
		Set S_RZPARAM=new RZPARAM
		
		If page=0 Then 
			S_RZPARAM.QueryString=proc&lang&"-t"&path&".html"
			filepath=GetPath(RZ_HTML_PATH&"/"&proc&lang&"/t"&static_path&".html")
		Else 
			S_RZPARAM.QueryString=proc&lang&"-t"&path&"p"&page&".html"
			filepath=GetPath(RZ_HTML_PATH&"/"&proc&lang&"/t"&static_path&"p"&page&".html")
		End If 
		Set S_CRUMB=new RZCrumb
		S_TEMPLATE=""
		S_HTMLMBUFFER=""
		Select Case proc
			Case RZ_PRE_ARTICLE_LIST:
				Call Articlelist(1)
			Case RZ_PRE_PRODUCT_LIST:
				Call Productlist(1)
			Case RZ_PRE_PHOTO_LIST:
				Call Photolist(1)
			Case RZ_PRE_JOB_LIST:
				Call Joblist(1)
		End Select 
		Call CreateFolders(GetPath(RZ_HTML_PATH&"/"&proc&lang))
		Call SaveFile(filepath,S_HTMLMBUFFER)
	Next 
End Function 

'更新分类修改时间
Function updateTypeModifytime(path,nowtime)
Dim patharr,i
patharr=Split(path,",")
For i=0 To UBound(patharr)
	Dim sql,rs
	Set rs = Server.CreateObject("ADODB.Recordset")
	sql = "select * from [c_type] where id="&patharr(i)
	rs.open sql,conn,1,3
	If Not rs.eof Then 
		rs("modifytime")=nowtime
		rs.update
	End If 
	rs.close
	Set rs=Nothing 
next
End Function 

Function updateSpecialModifytime(specialid,nowtime)
Dim sql,rs
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select * from [c_special] where id="&specialid
rs.open sql,conn,1,3
If Not rs.eof Then 
	rs("modifytime")=nowtime
	rs.update
End If 
rs.close
Set rs=Nothing 
End Function 

Function Singleton()
Dim sql,rs,result
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select * from [c_type] where fenlei=6 order by path,theorder"
rs.open sql,conn,1,1
Do While  Not rs.eof
result=result&"<div><a href=""type_edit.asp?id="&rs("id")&""" title="""&rs("name")&""" target=""mainFrame"">+"&rs("name")&"</a></div>"
rs.movenext
Loop 
rs.close
Set rs=Nothing 
response.write(result)
End Function 

%>